<template>
  <div class="question-item" :class="{ 'blue-background': info.role === 'user' }">
    <img v-if="info.role === 'user'" class="question-item-img" src="@/assets/bg/logo.png" alt="">
    <template v-else>
      <img v-if="type === 'spark'" class="question-item-img" src="@/assets/bg/logo.png" alt="">
    </template>
    <div class="question-item-text">
      <span class="text" v-if="info.role === 'user'" v-html="info.content"></span>
      <Markdown v-else :source="info.content" />
      <div class="line" v-if="blink"></div>
    </div>
  </div>
</template>

<script>
import Markdown from 'vue3-markdown-it';
import 'highlight.js/styles/a11y-dark.css';
export default {
  name: 'QuestionItem', // 对话框
  components: {
    Markdown
  },
  props: {
    info: {
      type: Object,
      default: {
        role: 'user',
        content: ''
      }
    },
    blink: {
      type: Boolean,
      default: false
    },
    type: {
      type: String,
      default: 'spark'
    }
  },
  methods: {

  }
}
</script>

<style lang="less" scoped>
@keyframes blink {
  from {
    background: linear-gradient(to right, var(--text-color), var(--text-color));
  }

  to {
    background: transparent;
  }
}

.question-item {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  padding: 10px;

  &-img {
    width: 30px;
    height: 30px;
    margin: 10px;
  }

  &-text {
    width: calc(100% - 100px);
    box-sizing: border-box;
    padding: 10px 25px;
    background: white;
    border-radius: 5px;
    line-height: 30px;
    text-align: left;

    .line {
      position: relative;
      top: 3px;
      display: inline-block;
      width: 2px;
      height: 20px;
      background: var(--text-color);
      animation: blink .8s infinite;
    }
  }

  &.blue-background {
    flex-direction: row-reverse;

    .question-item-text {
      background: var(--theme-color);
      color: white;
    }
  }
}
</style>